<template>
  <div class="app-container">
    <div class="syl-group">
      <el-form ref="queryForm" :model="queryParams" :inline="true">
        <el-form-item label="选择时间:">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            size="small"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          <el-button icon="el-icon-refresh" size="mini" class="ordinary" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="equWristbandList" :header-cell-style="{background:'#F3F9FF',color:'#333333',fontWeight: 600}">
        <el-table-column label="评价时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
        <el-table-column label="订单编号" align="center" prop="orderNo" :show-overflow-tooltip="true" />
        <el-table-column label="套餐名称" align="center" prop="packageName" :show-overflow-tooltip="true" />
        <el-table-column label="评分" align="center" prop="evaluateScore" />
        <el-table-column label="评价内容" align="center" prop="content" :show-overflow-tooltip="true" />
        <el-table-column label="评价图片" align="center" prop="evaluateImage">
          <template slot-scope="score">
            <img
              v-for="(item,index) in getImg(score.row.evaluateImage)"
              :key="index"
              :src="serverMap.baseImg+'/'+item"
              alt=""
              style="width: 80px;height: 60px; margin: 0  8px;cursor: pointer"
              @click="getImgValue(serverMap.baseImg+'/'+item)"
            >
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
            >查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- 添加或修改门店对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <div class="syl-evaluation">
            <div class="evaluation-left" v-html="'评价目标:'+form.packageName" />
            <div class="evaluation-right" v-html="form.createTime" />
          </div>
          <div class="syl-evaluation" v-html="'公司名称:'+form.companyName" />
          <div class="syl-evaluation">
            <el-rate v-model="form.evaluateScore" show-text :disabled="true" />
          </div>
          <div class="contents" v-html="form.content" />
          <img
            v-for="(item,index) in getImg(form.evaluateImage)"
            :key="index"
            :src="serverMap.baseImg+'/'+item"
            alt=""
            style="width: 107px;height: 107px; margin: 0  8px"
          >
        </el-col>
        <el-col :span="12">
          <div class="syl-evaluation" style="color: #333333">订单信息:</div>
          <div class="syl-evaluation">
            <span style="color: #333333;font-weight: 600;font-size: 16px">订单编号:</span>
            <span v-html="form.orderNo" />
          </div>
          <div class="syl-evaluation">
            <span style="color: #333333;font-weight: 600;font-size: 16px">订单金额:</span>
            <span v-html="form1.orderMoney" />
          </div>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">关 闭</el-button>
      </div>
    </el-dialog>
    <!--照片弹窗-->
    <el-dialog
      :title="title1"
      :visible.sync="dialogVisible"
      width="400px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div style="width: 100%;text-align: center">
        <img style="max-width: 240px;height: 170px" :src="dialogImageUrl" alt="">
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getDishesList, getById } from '@/api/evaluate/dishesEvaluation'
import { getCompanyOrderInfo } from '@/api/order'
import serverMap from '../../../../config/serverMap'

export default {
  name: 'Index',
  data() {
    return {
      // 照片回显
      dialogImageUrl: null,
      serverMap: serverMap,
      // 日期
      dateRange: [],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 评价表格数据
      equWristbandList: [],
      // 状态
      options: [],
      // 弹出层标题
      title: '',
      title1: '',
      // 是否显示弹出层
      open: false,
      dialogVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {
        anonymityStatus: null,
        companyId: null,
        companyName: null,
        content: null,
        createId: null,
        createTime: null,
        delFlag: null,
        employeeId: null,
        employeeName: null,
        evaluateImage: null,
        evaluateScore: null,
        id: null,
        orderId: null,
        orderNo: null,
        packageId: null,
        packageName: null,
        remarks: null,
        updateId: null,
        updateTime: null,
        version: null
      },
      form1: {
        orderMoney: null
      },
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询套餐评价列表数据 */
    getList() {
      getDishesList(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
        const { total, records } = res.data
        this.total = total
        this.equWristbandList = records
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        anonymityStatus: undefined,
        companyId: undefined,
        companyName: undefined,
        content: undefined,
        createId: undefined,
        createTime: undefined,
        delFlag: undefined,
        employeeId: undefined,
        employeeName: undefined,
        evaluateImage: undefined,
        evaluateScore: undefined,
        id: undefined,
        orderId: undefined,
        orderNo: undefined,
        packageId: undefined,
        packageName: undefined,
        remarks: undefined,
        updateId: undefined,
        updateTime: undefined,
        version: undefined
      }
      this.form1 = {
        orderMoney: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = []
      this.handleQuery()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getNameId(row)
      this.handleStatusChange(row)
      this.title = '查看评价'
      this.open = true
    },
    /** 评价内容**/
    getNameId(row) {
      getById(row.id).then(res => {
        this.form = res.data
      })
    },
    /** 订单信息 **/
    handleStatusChange(row) {
      getCompanyOrderInfo(row.orderId).then(res => {
        const { order } = res.data
        this.form1.orderMoney = order.orderMoney
      })
    },
    /** 提交按钮 */
    submitForm: function() {
      this.open = false
    },
    /** 处理图片 **/
    getImg(val) {
      const arr = [null, undefined, '']
      if (arr.includes(val)) {
        return []
      }
      return val.split(',')
    },
    /** 查看图片 **/
    getImgValue(row) {
      this.dialogImageUrl = row
      this.dialogVisible = true
      this.title1 = '查看照片'
    }
  }
}
</script>

<style lang="scss" scoped>
.syl-evaluation {
  height: 40px;
  line-height: 40px;
  font-size: 16px;
  font-weight: 600;
  .evaluation-left {
    text-align: left;
    color: #333333;
    font-weight: 600;
    float: left;
  }

  .evaluation-right {
    text-align: right;
    color: #999999;
    font-weight: 500;
    font-size: 14px;
    float: right;
  }
}

.contents {
  height: 122px;
  text-align: center;
  background: #F7F7F7;
  padding: 8px;
  border-radius: 4px 4px 0 0;
  color: #999999;
  font-size: 14px;
  font-weight: 500;
}
/deep/.el-dialog{
  border-radius: 12px;
  background: #FFFFFF;
  padding: 0 20px;
}
</style>
